package org.budo.cmbc.direct.sdk.impl;

import org.budo.cmbc.direct.sdk.CmbcDirectBankSdk;
import org.budo.cmbc.direct.sdk.entity.MEAccountAssetsQueryRequest;
import org.budo.cmbc.direct.sdk.entity.MEAccountAssetsQueryResponse;
import org.budo.cmbc.direct.sdk.entity.MEAccountOpenQueryRequest;
import org.budo.cmbc.direct.sdk.entity.MEAccountOpenQueryResponse;
import org.budo.cmbc.direct.sdk.entity.MEAccountOpenRequest;
import org.budo.cmbc.direct.sdk.entity.MEAccountOpenResponse;
import org.budo.cmbc.direct.sdk.entity.MEAccountQueryRequest;
import org.budo.cmbc.direct.sdk.entity.MEAccountQueryResponse;
import org.budo.cmbc.direct.sdk.entity.MEAccountUnLockRequest;
import org.budo.cmbc.direct.sdk.entity.MEAccountUnLockResponse;
import org.budo.cmbc.direct.sdk.entity.MEActiveIIIPayeeAcctRequest;
import org.budo.cmbc.direct.sdk.entity.MEActiveIIIPayeeAcctResponse;
import org.budo.cmbc.direct.sdk.entity.MEAddrListQryRequest;
import org.budo.cmbc.direct.sdk.entity.MEAddrListQryResponse;
import org.budo.cmbc.direct.sdk.entity.MEBankInnerPathQueryRequest;
import org.budo.cmbc.direct.sdk.entity.MEBankInnerPathQueryResponse;
import org.budo.cmbc.direct.sdk.entity.MEBankInnerPathSignRequest;
import org.budo.cmbc.direct.sdk.entity.MEBankInnerPathSignResponse;
import org.budo.cmbc.direct.sdk.entity.MECloseAccountRequest;
import org.budo.cmbc.direct.sdk.entity.MECloseAccountResponse;
import org.budo.cmbc.direct.sdk.entity.MECloseAccountResultQueryRequest;
import org.budo.cmbc.direct.sdk.entity.MECloseAccountResultQueryResponse;
import org.budo.cmbc.direct.sdk.entity.MECustInfoCheckRequest;
import org.budo.cmbc.direct.sdk.entity.MECustInfoCheckResponse;
import org.budo.cmbc.direct.sdk.entity.MECustInfoMaintenRequest;
import org.budo.cmbc.direct.sdk.entity.MECustInfoMaintenResponse;
import org.budo.cmbc.direct.sdk.entity.MEEAcnoTrsJnlQueryRequest;
import org.budo.cmbc.direct.sdk.entity.MEEAcnoTrsJnlQueryResponse;
import org.budo.cmbc.direct.sdk.entity.MEIIIAccountOpenRequest;
import org.budo.cmbc.direct.sdk.entity.MEIIIAccountOpenResponse;
import org.budo.cmbc.direct.sdk.entity.MELEBankRouterOutTransferRequest;
import org.budo.cmbc.direct.sdk.entity.MELEBankRouterOutTransferResponse;
import org.budo.cmbc.direct.sdk.entity.MELEBankRouterQueryRequest;
import org.budo.cmbc.direct.sdk.entity.MELEBankRouterQueryResponse;
import org.budo.cmbc.direct.sdk.entity.MELECardBinQueryRequest;
import org.budo.cmbc.direct.sdk.entity.MELECardBinQueryResponse;
import org.budo.cmbc.direct.sdk.entity.MELEGenerateRandRequest;
import org.budo.cmbc.direct.sdk.entity.MELEGenerateRandResponse;
import org.budo.cmbc.direct.sdk.entity.MELEGetPhoneCodeRequest;
import org.budo.cmbc.direct.sdk.entity.MELEGetPhoneCodeResponse;
import org.budo.cmbc.direct.sdk.entity.MELEIdPhotoUploadRequest;
import org.budo.cmbc.direct.sdk.entity.MELEIdPhotoUploadResponse;
import org.budo.cmbc.direct.sdk.entity.MELEIdPhotoUploadResultRequest;
import org.budo.cmbc.direct.sdk.entity.MELEIdPhotoUploadResultResponse;
import org.budo.cmbc.direct.sdk.entity.MEOccupationListQryRequest;
import org.budo.cmbc.direct.sdk.entity.MEOccupationListQryResponse;
import org.budo.cmbc.direct.sdk.entity.MEPreCloseAccountRequest;
import org.budo.cmbc.direct.sdk.entity.MEPreCloseAccountResponse;
import org.budo.cmbc.direct.sdk.entity.MEQryTransStatusRequest;
import org.budo.cmbc.direct.sdk.entity.MEQryTransStatusResponse;
import org.budo.cmbc.direct.sdk.entity.changeaccountinfo.MEApprovalProcessListQueryRequest;
import org.budo.cmbc.direct.sdk.entity.changeaccountinfo.MEApprovalProcessListQueryResponse;
import org.budo.cmbc.direct.sdk.entity.changeaccountinfo.MEApprovalProcessQueryRequest;
import org.budo.cmbc.direct.sdk.entity.changeaccountinfo.MEApprovalProcessQueryResponse;
import org.budo.cmbc.direct.sdk.entity.changeaccountinfo.MEBindCardChangeApprovalApplyRequest;
import org.budo.cmbc.direct.sdk.entity.changeaccountinfo.MEBindCardChangeApprovalApplyResponse;
import org.budo.cmbc.direct.sdk.entity.changeaccountinfo.MEBindCardChangeByApprovalRequest;
import org.budo.cmbc.direct.sdk.entity.changeaccountinfo.MEBindCardChangeByApprovalResponse;
import org.budo.cmbc.direct.sdk.entity.changeaccountinfo.MEBindCardChangeRequest;
import org.budo.cmbc.direct.sdk.entity.changeaccountinfo.MEBindCardChangeResponse;
import org.budo.cmbc.direct.sdk.entity.changeaccountinfo.MEPhoneChangeForOldPhoneMsgRequest;
import org.budo.cmbc.direct.sdk.entity.changeaccountinfo.MEPhoneChangeForOldPhoneMsgResponse;
import org.budo.cmbc.direct.sdk.entity.changeaccountinfo.MEPhoneChangeWithoutOldPhoneMsgRequest;
import org.budo.cmbc.direct.sdk.entity.changeaccountinfo.MEPhoneChangeWithoutOldPhoneMsgResponse;
import org.budo.cmbc.direct.sdk.entity.changeaccountinfo.METransPasswordChangeRequest;
import org.budo.cmbc.direct.sdk.entity.changeaccountinfo.METransPasswordChangeResponse;
import org.budo.cmbc.direct.sdk.entity.changeaccountinfo.METransPasswordResetApplyRequest;
import org.budo.cmbc.direct.sdk.entity.changeaccountinfo.METransPasswordResetApplyResponse;
import org.budo.cmbc.direct.sdk.entity.changeaccountinfo.METransPasswordResetRequest;
import org.budo.cmbc.direct.sdk.entity.changeaccountinfo.METransPasswordResetResponse;
import org.budo.cmbc.direct.sdk.entity.changeaccountinfo.METransPasswordUnlockRequest;
import org.budo.cmbc.direct.sdk.entity.changeaccountinfo.METransPasswordUnlockResponse;
import org.springframework.util.Assert;

import java.util.HashMap;
import java.util.Map;

/**
 * @author lmw
 */
public class CmbcDirectBankSdkImpl extends AbstractCmbcDirectBankSdk implements CmbcDirectBankSdk {
    @Override
    public MELEGetPhoneCodeResponse MELEGetPhoneCode(MELEGetPhoneCodeRequest request) {
        // 构建业务数据，需要注意的是，所有业务数据都需要放在dataMap中，渠道流水号、商户号不需要放在dataMap中
        Map<String, Object> dataMap = new HashMap<String, Object>(8);
        // 场景类型 C01:开户场景获取短信验证码
        dataMap.put("TemplateId", request.getTemplateId());
        // 手机号
        dataMap.put("MobilePhone", request.getMobilePhone());
        String generateChannelJnlNo = setEProtocolAcNoAndChannelJnlNo(request, dataMap);

        // 参数1.交易码 参数2.业务数据Map 参数3.交易流水号
        String responseJson = this.messeageSender().sendMessage("MELEGetPhoneCode", dataMap, generateChannelJnlNo);

        return new MELEGetPhoneCodeResponse(generateChannelJnlNo, responseJson);
    }

    /**
     * 开户请求在少数情况下可能被转为异步处理（EAcNoStatus=02或EAcNoStatus=null或为空）
     */
    @Override
    public MEAccountOpenResponse MEAccountOpen(MEAccountOpenRequest request) {
        Map<String, Object> dataMap = new HashMap<>(32);
        // 上传设备ip
        dataMap.put("ClientIpAddr", request.getClientIpAddr());

        // 是否如意宝签约 0-签约 1-不签约
        dataMap.put("IsSignFund", "1");
        // 是否同意开户协议 0-同意 1-不同意
        dataMap.put("IsAgreeProtocol", "0");
        // 仅中国税收居民 Y-仅中国税收居民 N-不仅中国税收居民
        dataMap.put("CrsPersonState", "Y");
        // 是否开通三类户
        dataMap.put("OpenPayeeAcctFlag", "Y");

        // 客户姓名
        dataMap.put("CifName", request.getCifName());
        // 身份证
        dataMap.put("IdNo", request.getIdNo());
        // 手机号码
        dataMap.put("MobilePhone", request.getMobilePhone());
        // 绑定卡卡号
        dataMap.put("TAcNo", request.getTAcNo());

        // 密码随机数流水号
        dataMap.put("RandJnlNo", request.getRandJnlNo());
        dataMap.put("Random", request.getRandom());

        // 短信验证码Id
        dataMap.put("MessageTaskId", request.getMessageTaskId());
        // 短信验证码
        dataMap.put("MessageCode", request.getMessageCode());

        // 电子账户交易密码密文
        dataMap.put("PwdResult", request.getPwdResult());
        // 电子账户交易密码密文确认
        dataMap.put("PwdResultConfirm", request.getPwdResultConfirm());

        // 身份证照片验证凭证号 此字段由上传身份证照片返回
        dataMap.put("IdPNo", request.getIdPNo());

        // 补充区/县代码
        dataMap.put("DistrictCode", request.getDistrictCode());
        // 补充详细街道地址
        dataMap.put("Street", request.getStreet());
        // 补充职业代码
        dataMap.put("Occupation", request.getOccupation());
        // 补充工作单位信息
        dataMap.put("Company", request.getCompany());
        // 职业备注
        dataMap.put("OccupationRemark", request.getOccupationRemark());

        String generateChannelJnlNo = this.setEProtocolAcNoAndChannelJnlNo(request, dataMap);

        String responseJson = this.messeageSender().sendMessage("MEAccountOpen", dataMap, generateChannelJnlNo);

        return new MEAccountOpenResponse(generateChannelJnlNo, responseJson);
    }

    @Override
    public MELEIdPhotoUploadResultResponse MELEIdPhotoUploadResult(MELEIdPhotoUploadResultRequest request) {
        Assert.hasText(request.getIdNo(), "#72 IdNo 不允许为空");

        Map<String, Object> dataMap = new HashMap<String, Object>(8);
        dataMap.put("IdNo", request.getIdNo());

        String generateChannelJnlNo = setEProtocolAcNoAndChannelJnlNo(request, dataMap);

        String responseJson = this.messeageSender().sendMessage("MELEIdPhotoUploadResult", dataMap, generateChannelJnlNo);

        return new MELEIdPhotoUploadResultResponse(generateChannelJnlNo, responseJson);
    }

    @Override
    public MELEIdPhotoUploadResponse MELEIdPhotoUpload(MELEIdPhotoUploadRequest request) {
        Assert.hasText(request.getIdNo(), "#82 IdNo 不允许为空");
        Assert.hasText(request.getCifName(), "#83 CifName 不允许为空");
        Assert.hasText(request.getIdPASide(), "#84 IdPASide 不允许为空");
        Assert.hasText(request.getIdPBSide(), "#85 IdPBSide 不允许为空");

        Map<String, Object> dataMap = new HashMap<>(8);
        dataMap.put("IdNo", request.getIdNo());
        dataMap.put("CifName", request.getCifName());
        dataMap.put("IdPASide", request.getIdPASide());
        dataMap.put("IdPBSide", request.getIdPBSide());
        dataMap.put("EProtocolAcNo", request.getEProtocolAcNo());

        String generateChannelJnlNo = setEProtocolAcNoAndChannelJnlNo(request, dataMap);
        String responseJson = this.messeageSender().sendMessage("MELEIdPhotoUpload", dataMap, generateChannelJnlNo);
        return new MELEIdPhotoUploadResponse(generateChannelJnlNo, responseJson);
    }

    @Override
    public MECustInfoCheckResponse MECustInfoCheck(MECustInfoCheckRequest request) {
        Map<String, Object> dataMap = new HashMap<>(8);
        dataMap.put("TransType", request.getTransType());
        dataMap.put("IdNo", request.getIdNo());
        dataMap.put("CifName", request.getCifName());

        String generateChannelJnlNo = setEProtocolAcNoAndChannelJnlNo(request, dataMap);
        String responseJson = this.messeageSender().sendMessage("MECustInfoCheck", dataMap, generateChannelJnlNo);
        return new MECustInfoCheckResponse(generateChannelJnlNo, responseJson);
    }

    @Override
    public MELECardBinQueryResponse MELECardBinQuery(MELECardBinQueryRequest request) {
        Map<String, Object> dataMap = new HashMap<String, Object>(4);
        // 必填参数
        dataMap.put("TAcNo", request.getTAcNo());

        String generateChannelJnlNo = setEProtocolAcNoAndChannelJnlNo(request, dataMap);

        String responseJson = this.messeageSender().sendMessage("MELECardBinQuery", dataMap, generateChannelJnlNo);
        return new MELECardBinQueryResponse(generateChannelJnlNo, responseJson);
    }

    @Override
    public MELEGenerateRandResponse MELEGenerateRand(MELEGenerateRandRequest request) {
        Map<String, Object> dataMap = new HashMap<String, Object>(4);
        dataMap.put("RandType", request.getRandType());

        String generateChannelJnlNo = setEProtocolAcNoAndChannelJnlNo(request, dataMap);

        String responseJson = this.messeageSender().sendMessage("MELEGenerateRand", dataMap, generateChannelJnlNo);

        return new MELEGenerateRandResponse(generateChannelJnlNo, responseJson);
    }

    @Override
    public MEAccountOpenQueryResponse MEAccountOpenQuery(MEAccountOpenQueryRequest request) {
        Map<String, Object> dataMap = new HashMap<String, Object>(4);
        dataMap.put("OriginateChannelSerialNo", request.getOriginateChannelSerialNo());

        String generateChannelJnlNo = this.setEProtocolAcNoAndChannelJnlNo(request, dataMap);

        String responseJson = this.messeageSender().sendMessage("MEAccountOpenQuery", dataMap, generateChannelJnlNo);

        return new MEAccountOpenQueryResponse(generateChannelJnlNo, responseJson);
    }

    @Override
    public MEActiveIIIPayeeAcctResponse MEActiveIIIPayeeAcct(MEActiveIIIPayeeAcctRequest request) {
        Map<String, Object> dataMap = new HashMap<String, Object>(8);
        String generateChannelJnlNo = this.setEProtocolAcNoAndChannelJnlNo(request, dataMap);
        // 入金标志：1：需要做绑定卡入金 2: 不需要做绑定卡入金 默认需要绑卡入金。
        dataMap.put("IncomeFlag", "1");

        // 密码随机数流水号
        this.setPwdResultFields(request, dataMap);

        dataMap.put("TAcNo", request.getTAcNo());
        dataMap.put("Amount", request.getAmount());
        dataMap.put("PwdResult", request.getPwdResult());

        String responseJson = this.messeageSender().sendMessage("MEActiveIIIPayeeAcct", dataMap, generateChannelJnlNo);
        return new MEActiveIIIPayeeAcctResponse(generateChannelJnlNo, responseJson);
    }

    @Override
    public MECustInfoMaintenResponse MECustInfoMainten(MECustInfoMaintenRequest request) {
        Map<String, Object> dataMap = new HashMap<String, Object>(8);
        String generateChannelJnlNo = setEProtocolAcNoAndChannelJnlNo(request, dataMap);
        dataMap.put("Occupation", request.getOccupation());
        dataMap.put("OccupationRemark", request.getOccupationRemark());
        dataMap.put("DistrictCode", request.getDistrictCode());
        dataMap.put("Street", request.getStreet());
        dataMap.put("Company", request.getCompany());

        String responseJson = this.messeageSender().sendMessage("MECustInfoMainten", dataMap, generateChannelJnlNo);
        return new MECustInfoMaintenResponse(generateChannelJnlNo, responseJson);
    }

    @Override
    public MEOccupationListQryResponse MEOccupationListQry(MEOccupationListQryRequest request) {
        Map<String, Object> dataMap = new HashMap<>(4);

        String generateChannelJnlNo = setEProtocolAcNoAndChannelJnlNo(request, dataMap);

        String responseJson = this.messeageSender().sendMessage("MEOccupationListQry", dataMap, generateChannelJnlNo);
        return new MEOccupationListQryResponse(generateChannelJnlNo, responseJson);
    }

    @Override
    public MEAddrListQryResponse MEAddrListQry(MEAddrListQryRequest request) {
        Map<String, Object> dataMap = new HashMap<>(4);

        String generateChannelJnlNo = setEProtocolAcNoAndChannelJnlNo(request, dataMap);

        String responseJson = this.messeageSender().sendMessage("MEAddrListQry", dataMap, generateChannelJnlNo);
        return new MEAddrListQryResponse(generateChannelJnlNo, responseJson);
    }

    @Override
    public MEAccountQueryResponse MEAccountQuery(MEAccountQueryRequest request) {
        Map<String, Object> dataMap = new HashMap<String, Object>(4);
        String generateChannelJnlNo = this.setEProtocolAcNoAndChannelJnlNo(request, dataMap);

        String responseJson = this.messeageSender().sendMessage("MEAccountQuery", dataMap, generateChannelJnlNo);
        return new MEAccountQueryResponse(generateChannelJnlNo, responseJson);
    }

    @Override
    public MEAccountUnLockResponse MEAccountUnLock(MEAccountUnLockRequest request) {
        String[] fields = { "MessageTaskId", "MessageCode", "PwdResult", "RandJnlNo", "Random", "CifName", "IdNo", "MobilePhone", "TAcNo", "LockType" };
        Map<String, Object> dataMap = this.fieldValueMap(request, fields);
        String generateChannelJnlNo = this.setEProtocolAcNoAndChannelJnlNo(request, dataMap);
        String responseJson = this.messeageSender().sendMessage("MEAccountUnLock", dataMap, generateChannelJnlNo);
        return new MEAccountUnLockResponse(generateChannelJnlNo, responseJson);
    }

    @Override
    public MEAccountAssetsQueryResponse MEAccountAssetsQuery(MEAccountAssetsQueryRequest request) {
        Map<String, Object> dataMap = new HashMap<String, Object>(4);
        dataMap.put("EProtocolAcNo", request.getEProtocolAcNo());

        // 电子账户协议号
        String channelJnlNo = request.getChannelJnlNo();

        String responseJson = this.messeageSender().sendMessage("MEAccountAssetsQuery", dataMap, channelJnlNo);
        return new MEAccountAssetsQueryResponse(channelJnlNo, responseJson);
    }

    @Override
    public MEPreCloseAccountResponse MEPreCloseAccount(MEPreCloseAccountRequest request) {
        Map<String, Object> dataMap = new HashMap<String, Object>(8);
        String generateChannelJnlNo = this.setEProtocolAcNoAndChannelJnlNo(request, dataMap);
        dataMap.put("MessageTaskId", request.getMessageTaskId());
        dataMap.put("MessageCode", request.getMessageCode());
        dataMap.put("PwdResult", request.getPwdResult());
        dataMap.put("RandJnlNo", request.getRandJnlNo());
        dataMap.put("Random", request.getRandom());

        String responseJson = this.messeageSender().sendMessage("MEPreCloseAccount", dataMap, generateChannelJnlNo);
        return new MEPreCloseAccountResponse(generateChannelJnlNo, responseJson);
    }

    @Override
    public MECloseAccountResponse MECloseAccount(MECloseAccountRequest request) {
        Map<String, Object> dataMap = new HashMap<>(4);
        String generateChannelJnlNo = this.setEProtocolAcNoAndChannelJnlNo(request, dataMap);

        String responseJson = this.messeageSender().sendMessage("MECloseAccount", dataMap, generateChannelJnlNo);
        return new MECloseAccountResponse(generateChannelJnlNo, responseJson);
    }

    @Override
    public MECloseAccountResultQueryResponse MECloseAccountResultQuery(MECloseAccountResultQueryRequest request) {
        Map<String, Object> dataMap = new HashMap<>(4);
        String generateChannelJnlNo = this.setEProtocolAcNoAndChannelJnlNo(request, dataMap);

        String responseJson = this.messeageSender().sendMessage("MECloseAccountResultQuery", dataMap, generateChannelJnlNo);
        return new MECloseAccountResultQueryResponse(generateChannelJnlNo, responseJson);
    }

    @Override
    public MEIIIAccountOpenResponse MEIIIAccountOpen(MEIIIAccountOpenRequest request) {
        Map<String, Object> dataMap = new HashMap<>(4);

        String generateChannelJnlNo = this.setEProtocolAcNoAndChannelJnlNo(request, dataMap);
        String responseJson = this.messeageSender().sendMessage("MEIIIAccountOpen", dataMap, generateChannelJnlNo);
        return new MEIIIAccountOpenResponse(generateChannelJnlNo, responseJson);
    }

    @Override
    public MELEBankRouterOutTransferResponse MELEBankRouterOutTransfer(MELEBankRouterOutTransferRequest request) {
        Map<String, Object> dataMap = new HashMap<>(16);

        String generateChannelJnlNo = this.setEProtocolAcNoAndChannelJnlNo(request, dataMap);
        // 金额
        dataMap.put("Amount", request.getAmount());
        // 电子账户协议号
        dataMap.put("EProtocolAcNo", request.getEProtocolAcNo());
        // 汇款方式
        dataMap.put("PayPath", request.getPayPath());
        // 交易密码密文
        dataMap.put("PwdResult", request.getPwdResult());
        dataMap.put("RandJnlNo", request.getRandJnlNo());
        dataMap.put("Random", request.getRandom());
        // 转账用途
        dataMap.put("Remark", request.getRemark());

        String responseJson = this.messeageSender().sendMessage("MELEBankRouterOutTransfer", dataMap, generateChannelJnlNo);
        return new MELEBankRouterOutTransferResponse(generateChannelJnlNo, responseJson);
    }

    @Override
    public MELEBankRouterQueryResponse MELEBankRouterQuery(MELEBankRouterQueryRequest request) {
        Map<String, Object> dataMap = new HashMap<>(4);
        // 金额
        dataMap.put("Amount", request.getAmount());
        // 电子账户协议号

        String generateChannelJnlNo = this.setEProtocolAcNoAndChannelJnlNo(request, dataMap);
        String responseJson = this.messeageSender().sendMessage("MELEBankRouterQuery", dataMap, generateChannelJnlNo);
        return new MELEBankRouterQueryResponse(generateChannelJnlNo, responseJson);
    }

    @Override
    public MEEAcnoTrsJnlQueryResponse MEEAcnoTrsJnlQuery(MEEAcnoTrsJnlQueryRequest request) {
        Map<String, Object> dataMap = new HashMap<>(8);

        // 电子账户协议号
        // dataMap.put("EProtocolAcNo", request.getEProtocolAcNo());

        String generateChannelJnlNo = this.setEProtocolAcNoAndChannelJnlNo(request, dataMap);

        dataMap.put("BeginDate", request.getBeginDate());
        dataMap.put("EndDate", request.getEndDate());
        dataMap.put("BeginNumber", request.getBeginNumber());
        dataMap.put("QueryNumber", request.getQueryNumber());

        String responseJson = this.messeageSender().sendMessage("MEEAcnoTrsJnlQuery", dataMap, generateChannelJnlNo);
        return new MEEAcnoTrsJnlQueryResponse(generateChannelJnlNo, responseJson);
    }

    @Override
    public MEQryTransStatusResponse MEQryTransStatus(MEQryTransStatusRequest request) {

        Map<String, Object> dataMap = new HashMap<>(8);
        // 电子账户协议号
        String generateChannelJnlNo = setEProtocolAcNoAndChannelJnlNo(request, dataMap);
        dataMap.put("OriginateChannelSerialNo", request.getOriginateChannelSerialNo());
        dataMap.put("OriginateChannelDate", request.getOriginateChannelDate());

        String responseJson = this.messeageSender().sendMessage("MEQryTransStatus", dataMap, generateChannelJnlNo);
        return new MEQryTransStatusResponse(generateChannelJnlNo, responseJson);
    }

    @Override
    public MEPhoneChangeForOldPhoneMsgResponse MEPhoneChangeForOldPhoneMsg(MEPhoneChangeForOldPhoneMsgRequest request) {
        String[] fields = { "MessageTaskId", "MessageCode", "NewMessageTaskId", "NewMobilePhone", "NewMessageCode", "PwdResult", "RandJnlNo", "Random" };
        Map<String, Object> dataMap = this.fieldValueMap(request, fields);
        String generateChannelJnlNo = this.setEProtocolAcNoAndChannelJnlNo(request, dataMap);

        String responseJson = this.messeageSender().sendMessage("MEPhoneChangeForOldPhoneMsg", dataMap, generateChannelJnlNo);
        return new MEPhoneChangeForOldPhoneMsgResponse(generateChannelJnlNo, responseJson);
    }

    @Override
    public MEPhoneChangeWithoutOldPhoneMsgResponse MEPhoneChangeWithoutOldPhoneMsg(MEPhoneChangeWithoutOldPhoneMsgRequest request) {
        String[] fields = { "NewMessageTaskId", "NewMobilePhone", "NewMessageCode", "PwdResult", "RandJnlNo", "Random", "PhotoFront", "PhotoBack", "PhotoHold" };
        Map<String, Object> dataMap = this.fieldValueMap(request, fields);
        String generateChannelJnlNo = setEProtocolAcNoAndChannelJnlNo(request, dataMap);

        String responseJson = this.messeageSender().sendMessage("MEPhoneChangeWithoutOldPhoneMsg", dataMap, generateChannelJnlNo);
        return new MEPhoneChangeWithoutOldPhoneMsgResponse(generateChannelJnlNo, responseJson);
    }

    @Override
    public MEBindCardChangeResponse MEBindCardChange(MEBindCardChangeRequest request) {
        String[] fields = { "MessageTaskId", "MessageCode", "PwdResult", "RandJnlNo", "Random", "TAcNo" };
        Map<String, Object> dataMap = this.fieldValueMap(request, fields);
        String generateChannelJnlNo = this.setEProtocolAcNoAndChannelJnlNo(request, dataMap);

        String responseJson = this.messeageSender().sendMessage("MEBindCardChange", dataMap, generateChannelJnlNo);
        return new MEBindCardChangeResponse(generateChannelJnlNo, responseJson);
    }

    @Override
    public METransPasswordUnlockResponse METransPasswordUnlock(METransPasswordUnlockRequest request) {
        String[] fields = { "MessageTaskId", "MessageCode", "PwdResult", "RandJnlNo", "Random" };
        Map<String, Object> dataMap = this.fieldValueMap(request, fields);
        String generateChannelJnlNo = this.setEProtocolAcNoAndChannelJnlNo(request, dataMap);

        String responseJson = this.messeageSender().sendMessage("METransPasswordUnlock", dataMap, generateChannelJnlNo);
        return new METransPasswordUnlockResponse(generateChannelJnlNo, responseJson);
    }

    @Override
    public METransPasswordChangeResponse METransPasswordChange(METransPasswordChangeRequest request) {
        String[] fields = { "MessageTaskId", "MessageCode", "OldPwdResult", "OldRandJnlNo", "OldRandom", "NewPwdResult", "NewRandJnlNo", "NewRandom", "NewPwdResultConfirm" };
        Map<String, Object> dataMap = this.fieldValueMap(request, fields);
        String generateChannelJnlNo = this.setEProtocolAcNoAndChannelJnlNo(request, dataMap);

        String responseJson = this.messeageSender().sendMessage("METransPasswordChange", dataMap, generateChannelJnlNo);
        return new METransPasswordChangeResponse(generateChannelJnlNo, responseJson);
    }

    @Override
    public METransPasswordResetApplyResponse METransPasswordResetRequest(METransPasswordResetApplyRequest request) {
        String[] fields = { "MessageTaskId", "MessageCode", "PhotoFront", "PhotoBack", "PhotoHold" };
        Map<String, Object> dataMap = this.fieldValueMap(request, fields);
        String generateChannelJnlNo = this.setEProtocolAcNoAndChannelJnlNo(request, dataMap);

        String responseJson = this.messeageSender().sendMessage("METransPasswordResetRequest", dataMap, generateChannelJnlNo);
        return new METransPasswordResetApplyResponse(generateChannelJnlNo, responseJson);
    }

    @Override
    public METransPasswordResetResponse METransPasswordReset(METransPasswordResetRequest request) {
        String[] fields = { "MessageTaskId", "MessageCode", "RequestMessageCode", "PwdResult", "PwdResultConfirm", "RandJnlNo", "Random" };
        Map<String, Object> dataMap = this.fieldValueMap(request, fields);
        String generateChannelJnlNo = this.setEProtocolAcNoAndChannelJnlNo(request, dataMap);

        String responseJson = this.messeageSender().sendMessage("METransPasswordReset", dataMap, generateChannelJnlNo);
        return new METransPasswordResetResponse(generateChannelJnlNo, responseJson);
    }

    @Override
    public MEApprovalProcessQueryResponse MEApprovalProcessQuery(MEApprovalProcessQueryRequest request) {
        Map<String, Object> dataMap = new HashMap<String, Object>(16);
        dataMap.put("OriginateChannelSerialNo", request.getOriginateChannelSerialNo());
        String generateChannelJnlNo = this.setEProtocolAcNoAndChannelJnlNo(request, dataMap);
        String responseJson = this.messeageSender().sendMessage("MEApprovalProcessQuery", dataMap, generateChannelJnlNo);
        return new MEApprovalProcessQueryResponse(generateChannelJnlNo, responseJson);
    }

    @Override
    public MEApprovalProcessListQueryResponse MEApprovalProcessListQuery(MEApprovalProcessListQueryRequest request) {
        Map<String, Object> dataMap = new HashMap<>(16);
        String generateChannelJnlNo = this.setEProtocolAcNoAndChannelJnlNo(request, dataMap);
        String responseJson = this.messeageSender().sendMessage("MEApprovalProcessListQuery", dataMap, generateChannelJnlNo);
        return new MEApprovalProcessListQueryResponse(generateChannelJnlNo, responseJson);
    }

    @Override
    public MEBindCardChangeApprovalApplyResponse MEBindCardChangeApprovalApply(MEBindCardChangeApprovalApplyRequest request) {
        String[] fields = { "MessageTaskId", "MessageCode", "PwdResult", "RandJnlNo", "Random", "PhotoFront", "PhotoBack", "PhotoHold", "PhotoCardCancel", "TAcNo" };
        Map<String, Object> dataMap = this.fieldValueMap(request, fields);
        String generateChannelJnlNo = this.setEProtocolAcNoAndChannelJnlNo(request, dataMap);
        String responseJson = this.messeageSender().sendMessage("MEBindCardChangeApprovalRequest", dataMap, generateChannelJnlNo);
        return new MEBindCardChangeApprovalApplyResponse(generateChannelJnlNo, responseJson);
    }

    @Override
    public MEBindCardChangeByApprovalResponse MEBindCardChangeByApproval(MEBindCardChangeByApprovalRequest request) {
        String[] fields = { "MessageTaskId", "MessageCode", "RequestMessageCode", "PwdResult", "RandJnlNo", "Random", "TAcNo" };
        Map<String, Object> dataMap = this.fieldValueMap(request, fields);
        String generateChannelJnlNo = this.setEProtocolAcNoAndChannelJnlNo(request, dataMap);
        String responseJson = this.messeageSender().sendMessage("MEBindCardChangeByApproval", dataMap, generateChannelJnlNo);
        return new MEBindCardChangeByApprovalResponse(generateChannelJnlNo, responseJson);
    }

    @Override
    public MEBankInnerPathQueryResponse MEBankInnerPathQuery(MEBankInnerPathQueryRequest request) {
        String[] properties = { "TAcNo", "MobilePhone", "SendMsgFlag" };
        Map<String, Object> dataMap = this.fieldValueMap(request, properties);
        String generateChannelJnlNo = this.setEProtocolAcNoAndChannelJnlNo(request, dataMap);
        String responseJson = this.messeageSender().sendMessage("MEBankInnerPathQuery", dataMap, generateChannelJnlNo);
        return new MEBankInnerPathQueryResponse(generateChannelJnlNo, responseJson);
    }

    @Override
    public MEBankInnerPathSignResponse MEBankInnerPathSign(MEBankInnerPathSignRequest request) {
        String[] properties = { "BankInnerPath", "MessageCode", "TAcNo" };
        Map<String, Object> dataMap = this.fieldValueMap(request, properties);
        String generateChannelJnlNo = this.setEProtocolAcNoAndChannelJnlNo(request, dataMap);
        String responseJson = this.messeageSender().sendMessage("MEBankInnerPathSign", dataMap, generateChannelJnlNo);
        return new MEBankInnerPathSignResponse(generateChannelJnlNo, responseJson);
    }
}
